﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System
{
	public static class Common
	{

		public static void ExtractFile(String fn, int offset, int size, string res)
		{
			BinaryReader R = new BinaryReader(File.OpenRead(fn));
			R.BaseStream.Seek(offset, SeekOrigin.Begin);
			File.WriteAllBytes(res, R.ReadBytes(size));
			R.Close();
		}
		public static void InsertFile(String fn, int offset, int size, string src)
		{
			byte[] buf = File.ReadAllBytes(src);
			if (buf.Length != size)
				Console.WriteLine("Size: " + buf.Length + " Expected: " + size + " (" + (buf.Length - size) + ")");
			else
			{
				BinaryWriter W = new BinaryWriter(File.OpenWrite(fn));
				W.BaseStream.Seek(offset, SeekOrigin.Begin);
				W.Write(buf);
				W.Close();
				Console.WriteLine("Patched " + size + " bytes"); 
			}
		}
	}
}
